package com.rightsidetech.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.mall.dto.request.AuditRecordPageReq;
import com.rightsidetech.mall.dto.response.CommodityVerifyRecordResp;
import com.rightsidetech.mall.mapper.MallCommodityAuditRecordMapper;
import com.rightsidetech.mall.service.CommodityAuditRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import java.util.List;

@Service("commodityAuditRecordService")
public class CommodityAuditRecordServiceImpl implements CommodityAuditRecordService {

    @Resource
    private MallCommodityAuditRecordMapper mallCommodityAuditRecordMapper;

    @Override
    public ResponseData<PageInfo<CommodityVerifyRecordResp>> page(AuditRecordPageReq req) {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData<>(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        PageHelper.startPage(req.getPageNo(),req.getPageSize());
        List<CommodityVerifyRecordResp> result = mallCommodityAuditRecordMapper.selectPage(req);
        return ResponseData.success(new PageInfo<>(result));
    }
}
